﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MM.Commmon.UI;
using MM.Common.UI.Controls;
using DevExpress.XtraTreeList.Nodes;
using System.ComponentModel;
using MM.Common.DBBase;
using MM.Common.Base;
using DevExpress.XtraEditors;
using System.Windows.Forms;
using System.Drawing;
using System.Drawing.Drawing2D;
using DevExpress.XtraEditors.Controls;
using System.Data;

namespace MM.Common.Support
{
    public partial class FrmFormEdit : FrmBase
    {
        private TreeListNode formNode;
        public FrmFormEdit()
        {
            InitializeComponent();
        }

        public bool SetParameter(TreeListNode node)
        {
            if (this.Init())
            {
                this.formNode = node;
                string commandtext = "SELECT FORM_NAME ,OBJECT_NAME ,DESCRIBE ,MODULE_CODE FROM KTSYS_FORM WHERE FORM_CODE = :formcode";
                DataParamCol parm = new DataParamCol(new DataParam[] { new InputDataParam("formcode", node.GetValue("CODE").ToString()) });
                DataTable dt = new DataTable();
                SystemInfo.DbData.Retrieve(commandtext, parm, ref dt);
                this.txtFormCode.Text = node.GetValue("CODE").ToString();
                this.txtFormName.Text = dt.Rows[0]["FORM_NAME"].ToString();
                this.txtObjectName.Text = dt.Rows[0]["OBJECT_NAME"].ToString();
                this.txtDescribe.Text = dt.Rows[0]["DESCRIBE"].ToString();
                return true;
            }
            return false;
        }

        private void FrmFunctionEdit_Shown(object sender, EventArgs e)
        {
            this.txtFormCode.Focus();
        }

        private void btnExit_Click(object sender, EventArgs e)
        {
            base.DialogResult = System.Windows.Forms.DialogResult.Cancel;
            base.Close();
        }

        private void btnOk_Click(object sender, EventArgs e)
        {
            string text = this.txtFormCode.Text;
            string paramValue = this.txtFormName.Text;
            string str3 = this.txtObjectName.Text;
            string str4 = this.txtDescribe.Text;
            string commandtext = "UPDATE KTSYS_FORM SET FORM_NAME = :formname ,OBJECT_NAME = :objectname , DESCRIBE = :describe WHERE FORM_CODE = :formcode";
            DataParamCol parms = new DataParamCol(new DataParam[] { new InputDataParam("formname", paramValue), new InputDataParam("objectname", str3), new InputDataParam("describe", str4), new InputDataParam("formcode", text) });
            if (SystemInfo.DbData.ExecuteSql(commandtext, parms) >= 0)
            {
                this.formNode.SetValue("CODE", text);
                this.formNode.SetValue("NAME", paramValue);
                this.formNode.SetValue("OBJECT_NAME", str3);
                base.DialogResult = System.Windows.Forms.DialogResult.OK;
                base.Close();
            }
            else
            {
                XtraMessageBox.Show("更新不成功！\n原因：" + SystemInfo.DbData.ErrorMessage, "出错", MessageBoxButtons.OK, MessageBoxIcon.Hand);
            }
        }
    }
}
